home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
files.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
27KB
|
894 lines
{
$Id: files.pas,v 1.1.1.1 1998/03/25 11:18:12 root Exp $
Copyright (c) 1996-98 by Florian Klaempfl
This unit implements an extended file management and the first loading
and searching of the modules (ppufiles)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit files;
interface
uses
cobjects,globals;
const
{$ifdef FPC}
maxunits = 1024;
{$else}
maxunits = 128;
{$endif}
type
pextfile = ^textfile;
{ this isn't a text file, this is t-ext-file }
{ which means a extended file }
{ this files can be handled by a file }
{ manager }
textfile = object(tbufferedfile)
path,name,ext : pstring;
{ this is because there is a name conflict }
{ with the older next from tinputstack }
_next : pextfile;
{ 65000 input files for a unit should be enough !! }
ref_index : word;
{ p must be the complete path (with ending \ (or / for unix ...) }
constructor init(const p,n,e : string);
destructor done;virtual;
end;
pinputfile = ^tinputfile;
tinputfile = object(textfile)
filenotatend : boolean;
line_no : longint;
{ second counter for unimportant tokens }
line_count : longint;
{ next input file in the stack of input files }
next : pinputfile;
{ to handle the browser refs }
ref_count : longint;
constructor init(const p,n,e : string);
{ writes the file name and line number to t }
procedure write_file_line(var t : text);
function get_file_line : string;
end;
pfilemanager = ^tfilemanager;
tfilemanager = object
files : pextfile;
last_ref_index : word;
constructor init;
destructor done;
procedure close_all;
procedure register_file(f : pextfile);
end;
pimported_procedure = ^timported_procedure;
timported_procedure = object(tlinkedlist_item)
ordnr : word;
name,func : pstring;
{ should be plabel, but this gaves problems with circular units }
lab : pointer;
constructor init(const n,s : string;o : word);
destructor done;virtual;
end;
pimportlist = ^timportlist;
timportlist = object(tlinkedlist_item)
dllname : pstring;
imported_procedures : plinkedlist;
constructor init(const n : string);
destructor done;virtual;
end;
type
pmodule = ^tmodule;
pused_unit = ^tused_unit;
tused_unit = object(tlinkedlist_item)
u : pmodule;
in_uses, in_interface, is_stab_written : boolean;
unitid : word;
constructor init(_u : pmodule;f : byte);
destructor done;virtual;
end;
tunitmap = array[0..maxunits-1] of pointer;
punitmap = ^tunitmap;
tmodule = object(tlinkedlist_item)
{ the PPU file }
ppufile : pextfile;
{ used for global switches - in_main section after uses clause }
{ then TRUE else false. }
in_main : boolean;
{ mapping of all used units }
map : punitmap;
{ local unit counter }
unitcount : word;
{ this is a pointer because symtable uses this unit }
{ it should be psymtable }
symtable : pointer;
{ PPU version, handle different versions }
ppuversion : longint;
{ check sum written to the file }
crc : longint;
{ flags }
flags : byte;
{Set if the module imports from DLL's.}
uses_imports:boolean;
imports : plinkedlist;
{ how to write this file }
output_format : tof;
{ for interpenetrated units }
in_implementation,
compiled,
do_assemble,
do_compile, { true, if it's needed to compile the sources }
sources_avail : boolean; { true, if all sources are reachable }
{ only used, if the module is compiled by this compiler call }
sourcefiles : tfilemanager;
linklibfiles,
linkofiles : tstringcontainer;
used_units : tlinkedlist;
current_inputfile : pinputfile;
unitname, { name of the (unit) module }
objfilename, { fullname of the objectfile }
asmfilename, { fullname of the assemblerfile }
ppufilename, { fullname of the ppufile }
mainsource : pstring; { name of the main sourcefile }
constructor init(const s:string;is_unit:boolean);
{ this is to be called only when compiling again }
destructor special_done;virtual;
function load_ppu(const unit_path,n,ext : string):boolean;
procedure search_unit(const n : string);
end;
const
main_module : pmodule = nil;
current_module : pmodule = nil;
var
loaded_units : tlinkedlist;
type
tunitheader = array[0..19] of char;
const
{ compiler version }
{ format | }
{ signature | | }
{ | | | }
{ /-------\ /-------\ /----\ }
unitheader : tunitheader = ('P','P','U','0','1','3',#0,#99,
#0,#0,#0,#0,#0,#0,#255,#255,
{ | | \---------/ \-------/ }
{ | | | | }
{ | | check sum | }
{ | \--flags unused }
{ target system }
#0,#0,#0,#0);
{\---------/ }
{ | }
{ start of machine language }
const
ibloadunit = 1;
iborddef = 2;
ibpointerdef = 3;
ibtypesym = 4;
ibarraydef = 5;
ibprocdef = 6;
ibprocsym = 7;
iblinkofile = 8;
ibstringdef = 9;
ibvarsym = 10;
ibconstsym = 11;
ibinitunit = 12;
ibaufzaehlsym = 13;
ibtypedconstsym = 14;
ibrecorddef = 15;
ibfiledef = 16;
ibformaldef = 17;
ibobjectdef = 18;
ibenumdef = 19;
ibsetdef = 20;
ibprocvardef = 21;
ibsourcefile = 22;
ibdbxcount = 23;
ibfloatdef = 24;
ibref = 25;
ibextsymref = 26;
ibextdefref = 27;
ibabsolutesym = 28;
ibclassrefdef = 29;
ibpropertysym = 30;
iblibraries = 31;
iblongstringdef = 32;
ibansistringdef = 33;
ibend = 255;
{ unit flags }
uf_init = 1;
uf_uses_dbx = 2;
uf_uses_browser = 4;
uf_in_library = 8;
uf_shared_library = 16;
uf_big_